<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        html, body {
            height: 100%;
        }
        .box{
            position: absolute;
            top: 0;
            left: 0;
            width: 100px;
            height: 100px;
            background-color: pink;
            /* transition: all 0.7s; */
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <script>
        let box = document.querySelector('.box');
        function move(box, target, dir, cb) {
            let timer = setInterval(() => {
                let num = parseInt(getComputedStyle(box,null)[dir]);
                console.log(num);
                let step = 10 * (target > num ? 1 : -1);
                if(num === target) {
                    clearInterval(timer);
                    cb()
                } else {
                    box.style[dir] = num + step + 'px';
                }
            },100)
        }
        move(box,300,'left',function() {
            move(box,300,'top',function() {
                move(box,0,'left',function() {
                    move(box,0,'top',function() {
                        console.log('执行完毕');
                    })
                })
            })
        })
        
    </script>
</body>
</html>